d1f1157c6f4f97185fcfeab4d95d3ef0b1581d29
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?php
2
3 /**
4 * HOWTO
5 * Make sure index.php ends with the following lines (find the match for the first lines and replace the rest)
6
7 <?php
8 die();
9 }
10
11 require_once( './LocalSettings.php' );
12 require_once( 'includes/Setup.php' );
13
14 # The wiki action class
15 require_once ( "includes/Wiki.php" ) ;
16 ?>
17
18 */
19
20
21 #__________________________
22 #wiki class
23
24 class MediaWikiType {
25
26
27 #____________________________________________________________________________________
28 #Action methods
29
30 function act_view ( $action ) {
31 global $wgOut , $wgSquidMaxage , $wgArticle ;
32 $wgOut->setSquidMaxage( $wgSquidMaxage );
33 $wgArticle->view();
34 }
35
36 function act_print ( $action ) {
37 global $wgArticle ;
38 $wgArticle->view () ;
39 }
40
41 function act_dublincore ( $action ) {
42 global $wgArticle , $wgEnableDublinCoreRdf ;
43 if( !$wgEnableDublinCoreRdf ) {
44 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
45 } else {
46 require_once( 'includes/Metadata.php' );
47 wfDublinCoreRdf( $wgArticle );
48 }
49 }
50
51 function act_creativecommons ( $action ) {
52 global $wgArticle , $wgEnableCreativeCommonsRdf ;
53 if( !$wgEnableCreativeCommonsRdf ) {
54 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
55 } else {
56 require_once( 'includes/Metadata.php' );
57 wfCreativeCommonsRdf( $wgArticle );
58 }
59 }
60
61 function act_credits ( $action ) {
62 global $wgArticle ;
63 require_once( 'includes/Credits.php' );
64 showCreditsPage( $wgArticle );
65 }
66
67 function act_submit ( $action ) {
68 global $wgCommandLineMode , $wgRequest ;
69 if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
70 # Send a cookie so anons get talk message notifications
71 User::SetupSession();
72 }
73 $this->act_edit ( $action ) ;
74 }
75
76 function act_edit ( $action ) {
77 global $wgRequest , $wgUseExternalEditor , $wgUser , $wgArticle ;
78 $internal = $wgRequest->getVal( 'internaledit' );
79 $external = $wgRequest->getVal( 'externaledit' );
80 $section = $wgRequest->getVal( 'section' );
81 $oldid = $wgRequest->getVal( 'oldid' );
82 if(!$wgUseExternalEditor || $action=='submit' || $internal ||
83 $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
84 require_once( 'includes/EditPage.php' );
85 $editor = new EditPage( $wgArticle );
86 $editor->submit();
87 } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
88 require_once( 'includes/ExternalEdit.php' );
89 $mode = $wgRequest->getVal( 'mode' );
90 $extedit = new ExternalEdit( $wgArticle, $mode );
91 $extedit->edit();
92 }
93 }
94
95 function act_history ( $action ) {
96 global $wgTitle , $wgArticle , $wgSquidMaxage ;
97 if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
98 $wgOut->setSquidMaxage( $wgSquidMaxage );
99 }
100 require_once( 'includes/PageHistory.php' );
101 $history = new PageHistory( $wgArticle );
102 $history->history();
103 }
104
105 function act_raw ( $action ) {
106 global $wgArticle ;
107 require_once( 'includes/RawPage.php' );
108 $raw = new RawPage( $wgArticle );
109 $raw->view();
110 }
111
112
113 function action_unknown ( $action ) {
114 global $wgArticle , $wgOut ;
115 if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
116 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
117 }
118 }
119
120
121 function act_watch ( $action ) { $this->article_action ( $action ) ; }
122 function act_unwatch ( $action ) { $this->article_action ( $action ) ; }
123 function act_delete ( $action ) { $this->article_action ( $action ) ; }
124 function act_revert ( $action ) { $this->article_action ( $action ) ; }
125 function act_rollback ( $action ) { $this->article_action ( $action ) ; }
126 function act_protect ( $action ) { $this->article_action ( $action ) ; }
127 function act_unprotect ( $action ) { $this->article_action ( $action ) ; }
128 function act_info ( $action ) { $this->article_action ( $action ) ; }
129 function act_markpatrolled ( $action ) { $this->article_action ( $action ) ; }
130 function act_render ( $action ) { $this->article_action ( $action ) ; }
131 function act_deletetrackback ( $action ) { $this->article_action ( $action ) ; }
132 function act_purge ( $action ) { $this->article_action ( $action ) ; }
133
134 function article_action ( $action ) {
135 global $wgArticle ;
136 $wgArticle->$action() ;
137 }
138
139
140 } ; # end of class MediaWikiType
141
142
143 $wgTheWiki = new MediaWikiType ;
144
145
146
147
148
149 #global $wgRequest , $wgOut , $wgTitle , $wgContLang ;
150 #global $action , $title , $curid ;
151 OutputPage::setEncodings(); # Not really used yet
152 wfProfileIn( 'main-misc-setup' );
153
154 # Query string fields
155 $action = $wgRequest->getVal( 'action', 'view' );
156 $title = $wgRequest->getVal( 'title' );
157
158 if ($wgRequest->getVal( 'printable' ) == 'yes') {
159 $wgOut->setPrintable();
160 }
161
162 if ( '' == $title && 'delete' != $action ) {
163 $wgTitle = Title::newFromText( wfMsgForContent( 'mainpage' ) );
164 } elseif ( $curid = $wgRequest->getInt( 'curid' ) ) {
165 # URLs like this are generated by RC, because rc_title isn't always accurate
166 $wgTitle = Title::newFromID( $curid );
167 } else {
168 $wgTitle = Title::newFromURL( $title );
169 /* check variant links so that interwiki links don't have to worry about
170 the possible different language variants
171 */
172 if( count($wgContLang->getVariants()) > 1 && !is_null($wgTitle) && $wgTitle->getArticleID() == 0 )
173 $wgContLang->findVariantLink( $title, $wgTitle );
174
175 }
176 wfProfileOut( 'main-misc-setup' );
177
178 #global $search , $wgRequest , $wgTitle ;
179 $search = $wgRequest->getText( 'search' );
180 if( !is_null( $search ) && $search !== '' ) {
181 // Compatibility with old search URLs which didn't use Special:Search
182 // Do this above the read whitelist check for security...
183 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
184 }
185
186 #global $wgTitle , $wgOut ;
187 # If the user is not logged in, the Namespace:title of the article must be in
188 # the Read array in order for the user to see it. (We have to check here to
189 # catch special pages etc. We check again in Article::view())
190 if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
191 $wgOut->loginToUse();
192 $wgOut->output();
193 exit;
194 }
195
196 #global $wgTitle , $wgArticle , $wgRequest , $wgOut , $wgServer ;
197 #global $wgDisableInternalSearch , $wgUseCategoryMagic , $wgDisabledActions ;
198 #global $rdfrom , $url , $action , $ns , $rTitle , $search ;
199 wfProfileIn( 'main-action' );
200
201 if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
202 require_once( 'includes/SpecialSearch.php' );
203 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
204 wfSpecialSearch();
205 } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
206 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
207 $wgOut->errorpage( 'badtitle', 'badtitletext' );
208 } else if ( $wgTitle->getInterwiki() != '' ) {
209 if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
210 $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
211 } else {
212 $url = $wgTitle->getFullURL();
213 }
214 # Check for a redirect loop
215 if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
216 $wgOut->redirect( $url );
217 } else {
218 $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
219 $wgOut->errorpage( 'badtitle', 'badtitletext' );
220 }
221 } else if ( ( $action == 'view' ) &&
222 (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
223 !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
224 {
225 /* redirect to canonical url, make it a 301 to allow caching */
226 $wgOut->setSquidMaxage( 1200 );
227 $wgOut->redirect( $wgTitle->getFullURL(), '301');
228 } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
229 # actions that need to be made when we have a special pages
230 SpecialPage::executePath( $wgTitle );
231 } else {
232 if ( NS_MEDIA == $wgTitle->getNamespace() ) {
233 $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
234 }
235
236 $ns = $wgTitle->getNamespace();
237
238 // Namespace might change when using redirects
239 if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
240 $wgArticle = new Article( $wgTitle );
241 $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
242 if($rTitle) {
243 # Reload from the page pointed to later
244 $wgArticle->mContentLoaded = false;
245 $ns = $rTitle->getNamespace();
246 }
247 }
248
249 // Categories and images are handled by a different class
250 if ( $ns == NS_IMAGE ) {
251 unset($wgArticle);
252 require_once( 'includes/ImagePage.php' );
253 $wgArticle = new ImagePage( $wgTitle );
254 } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
255 unset($wgArticle);
256 require_once( 'includes/CategoryPage.php' );
257 $wgArticle = new CategoryPage( $wgTitle );
258 }
259
260 if ( in_array( $action, $wgDisabledActions ) ) {
261 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
262 } else {
263 $act = 'act_' . $action ;
264 if ( method_exists ( $wgTheWiki , $act ) ) {
265 $wgTheWiki->$act ( $action ) ;
266 } else {
267 $wgTheWiki->action_unknown ( $action ) ;
268 }
269 }
270 }
271
272 wfProfileOut( 'main-action' );
273 # }
274
275
276 # Deferred updates aren't really deferred anymore. It's important to report errors to the
277 # user, and that means doing this before OutputPage::output(). Note that for page saves,
278 # the client will wait until the script exits anyway before following the redirect.
279 wfProfileIn( 'main-updates' );
280 global $wgDeferredUpdateList ;
281 foreach ( $wgDeferredUpdateList as $up ) {
282 $up->doUpdate();
283 }
284 wfProfileOut( 'main-updates' );
285
286
287 #global $wgLoadBalancer , $wgOut , $wgPostCommitUpdateList ;
288 wfProfileIn( 'main-cleanup' );
289 $wgLoadBalancer->saveMasterPos();
290
291 # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
292 $wgLoadBalancer->commitAll();
293
294 $wgOut->output();
295
296 foreach ( $wgPostCommitUpdateList as $up ) {
297 $up->doUpdate();
298 }
299
300 wfProfileOut( 'main-cleanup' );
301
302 logProfilingData();
303 $wgLoadBalancer->closeAll();
304 wfDebug( "Request ended normally\n" );
305
306
307
308 ?>
309